<?php

class Admin extends Admin_Controller {

    function __construct() {
        parent::__construct();    
        
    }
    
    /**
     * List User
     * 
     * @desc Danh sách tài khoản
     */
    public function index() {            
        $arrVar    = array(
            'title_for_layout'  => 'User Admin Page'. $this->title
        );      
        $this->load->view('admin/index', $arrVar);
    }
    
    public function login() {    
        $this->load->library('form_validation');
        $validation = array(
            array(
                'field' => 'username',
                'label' => 'UserName',
                'rules' => 'required|alphanumeric|min_length[5]|max_length[30]'
            ),
            array(
                'field' => 'password',
                'label' => 'Password',
                'rules' => 'required|min_length[6]|max_length[30]'
            ),
        );
              
        // Set the validation rules
        $this->form_validation->set_rules($validation);
        // If the validation worked, or the user is already logged in
        if($this->form_validation->run()) { 
            $this->load->model('user_model');
            $username   = $this->input->post('username');
            $password   = $this->input->post('password');
            $query = $this->user_model->login($username, $password);
            
            if($query) { // if the user's credentials validated...
                $data = array(
                    'username' => $this->input->post('username'),
                    'is_logged_in' => true 
                );          
                $this->session->set_userdata($data);   
                redirect('admin/home');
            } 
        }
        else {        
            print_r($this->form_validation->error_string());
        }
        
        $arrVar    = array(
            'title_for_layout'  => 'Login Admin Page'. $this->title,
            'form_begin'        => form_open(base_url() .'admin/user/login', '', array('test1' => 123, 'test2' => "abc")),
            'form_end'          => form_close()
        );
        $this->load->view('admin/login', $arrVar);
    }
    
    public function logout() {
         $this->session->unset_userdata(array('is_logged_in'));
         redirect('admin/user/login');
    }
    
    /**
     * Add User
     * 
     * @desc Thêm mới tài khoản
     */
    public function add() {
        
    }
    
    /**
     * Edit User
     * 
     * @desc Sửa tài khoản
     */
    public function edit() {
        
    }
    
    /**
     * Delete User
     * 
     * @desc Xóa tài khoản
     */
    public function del() {
        
    }
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */